package com.yenlien.traceyun.plant.controller;

import com.alibaba.fastjson.JSONObject;
import com.yenlien.traceyun.business.dao.ProcessDetailDao;
import com.yenlien.traceyun.business.dao.SubpackageDao;
import com.yenlien.traceyun.business.entity.StorageManage;
import com.yenlien.traceyun.business.entity.Subpackage;
import com.yenlien.traceyun.plant.service.PlantStorageManageService;
import com.yenlien.traceyun.webase.controller.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author: bigwangy@sina.com
 * @create: 2020-12-22
 * @description:
 **/

@RestController
@RequestMapping(value = "/plant/storage")
public class PlantStorageController extends BaseController {

    @Autowired
    private SubpackageDao subpackageDao;

    @Autowired
    private ProcessDetailDao processDetailDao;

    @Autowired
    private PlantStorageManageService plantStorageManageService;

    /**
     * 入库
     *
     * @param params
     * @return
     */
    @RequestMapping(value = "/save", method = RequestMethod.POST)
    public Object save(@RequestBody JSONObject params) {
        List<StorageManage> storageManage = params.getJSONArray("storages").toJavaList(StorageManage.class);
        Subpackage subpackage = null;
        List<String> codes = null;
        if (params.containsKey("sub")) {
            subpackage = params.getJSONObject("sub").toJavaObject(Subpackage.class);
        }
        if (params.containsKey("codes")) {
            codes = params.getJSONArray("codes").toJavaList(String.class);
        }
        plantStorageManageService.save(storageManage, subpackage, codes);
        return success("success");
    }


}
